// PhasePerm.cpp : implementation file
//

#include "stdafx.h"
#include "VolDia.h"
#include "PhasePerm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern CVolDiaApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CPhasePerm dialog


CPhasePerm::CPhasePerm(CWnd* pParent /*=NULL*/)
	: CDialog(CPhasePerm::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPhasePerm)
	m_C2_4Door = FALSE;
	m_Z3Container = FALSE;
	m_TVActive = FALSE;
	m_Z3Cell = FALSE;
	//}}AFX_DATA_INIT
	m_fromMimic = false;
}


void CPhasePerm::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPhasePerm)
	DDX_Control(pDX, IDC_CMB_MAST, m_cmbMast);
	DDX_Check(pDX, IDC_C2_4DOOR, m_C2_4Door);
	DDX_Check(pDX, IDC_CONTAINER, m_Z3Container);
	DDX_Check(pDX, IDC_TV_ACTIVE, m_TVActive);
	DDX_Check(pDX, IDC_UNLOADCELL, m_Z3Cell);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPhasePerm, CDialog)
	//{{AFX_MSG_MAP(CPhasePerm)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPhasePerm message handlers

BOOL CPhasePerm::OnInitDialog() 
{
	CDialog::OnInitDialog();

	this->m_cmbMast.ResetContent();
	this->m_cmbMast.AddString(_T("MAIN MAST"));
	this->m_cmbMast.AddString(_T("NEW FUEL ROD"));
	this->m_cmbMast.AddString(_T("SPENT FUEL ROD"));
	this->m_cmbMast.SetCurSel(0);
	
	UpdateData(false);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPhasePerm::OnCancel() 
{
	if(!m_fromMimic)
		theApp.m_pDlg->m_pPhaseExecDialog->ShowWindow(SW_SHOWNORMAL);
	theApp.m_pDlg->m_pPhasePermDialog->CloseWindow();	
	CDialog::OnCancel();	
}

void CPhasePerm::LoadConditions(){
	
}

void CPhasePerm::OnOK() 
{
	RETSTAT		retSt;
	TCHAR		mast[20];

	UpdateData(true);
	/*
	retSt = SetDynStartCond(COND_CZ2Z4, this->m_C2_4Door);
	if(retSt != RT_NORMAL){
		MessageBox("Error setting start condition.", "Error", MB_OK);
		if(!m_fromMimic)
			theApp.m_pDlg->m_pPhaseExecDialog->EchoStrAdd("Error setting operation start permission.");
	}

	retSt = SetDynStartCond(COND_Z3CSK, this->m_Z3Container);
	if(retSt != RT_NORMAL){
		MessageBox("Error setting start condition.", "Error", MB_OK);
		if(!m_fromMimic)
			theApp.m_pDlg->m_pPhaseExecDialog->EchoStrAdd("Error setting operation start permission.");
	}

	retSt = SetDynStartCond(COND_Z3CELL, this->m_Z3Cell);
	if(retSt != RT_NORMAL){
		MessageBox("Error setting start condition.", "Error", MB_OK);
		if(!m_fromMimic)
			theApp.m_pDlg->m_pPhaseExecDialog->EchoStrAdd("Error setting operation start permission.");
	}

	retSt = SetDynStartCond(COND_TVAUTO, this->m_TVActive);
	if(retSt != RT_NORMAL){
		MessageBox("Error setting start condition.", "Error", MB_OK);
		if(!m_fromMimic)
			theApp.m_pDlg->m_pPhaseExecDialog->EchoStrAdd("Error setting operation start permission.");
	}
	*/
	if(!m_fromMimic){
		this->m_cmbMast.GetLBText(this->m_cmbMast.GetCurSel(), mast);
		if(!_tcscmp(mast, _T("MAIN MAST")))
			theApp.m_pDlg->m_pPhaseExecDialog->startMast = MAIN_MAST;
		
		retSt = SetDynCurrentMast(theApp.m_pDlg->m_pPhaseExecDialog->startMast);
		if(retSt != RT_NORMAL){
			MessageBox(_T("Error setting starting mast."), _T("Error"), MB_OK);
			theApp.m_pDlg->m_pPhaseExecDialog->EchoStrAdd(_T("Error setting starting mast."));
		}

		theApp.m_pDlg->m_pPhaseExecDialog->EchoStrAdd(_T("Phase permission sucessfully confirmed"));
		theApp.m_pDlg->m_pPhaseExecDialog->ShowWindow(SW_SHOWNORMAL);
	}
	
	CDialog::OnOK();
}

void CPhasePerm::CheckUser(void){





}
